home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 204_01 / sieve.c < prev    next >
Text File  |  1980-01-01  |  512b  |  30 lines

  1.  
  2. #define true 1
  3. #define false 0
  4. #define size 8190
  5. #define sizepl 8191
  6.  
  7. char    flags[sizepl];
  8.  
  9. main() {
  10.     int i,prime,k,count,iter;
  11.     printf("10 iterations\n");
  12.     for(iter=1;iter<= 10;iter++){
  13.         count=0;
  14.         for(i = 0; i<=size;i++)
  15.             flags[i]=true;
  16.         for(i=0;i <= size; i++){
  17.             if(flags[i]){
  18.                 prime = i+i+3;
  19.                 k=i+prime;
  20.                     while(k<=size){
  21.                         flags[k] = false;
  22.                         k += prime;
  23.                         }
  24.                     count = count+1;
  25.                 }
  26.             }
  27.         }
  28.     printf("\n%d primes\n",count);
  29.     }
  30.